package office.service.sale.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.bo.sale.impl.CustomerTracking;
import office.bo.sale.impl.TrackingInfo;
import office.domainset.BizDomainProviderSetImpl;
import office.service.sale.ITrackingService;
import platform.common.dao.IDomainProvider;
import platform.common.dao.impl.DaoConfigException;
import platform.common.dao.impl.DaoException;
import platform.common.service.impl.BaseBizServiceImpl;

public class TrackingService extends BaseBizServiceImpl implements ITrackingService {

	public void saveCustomerTracking(CustomerTracking customerTracking){
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().saveOrUpdate(customerTracking);
		} catch (DaoException e) {
			log.error("", e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<CustomerTracking> getCustomerTrackingByUidAndCustomer(String uid,String customerId){
		String params[] = {uid};
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerTrackingDP = domainProviderSetImpl.getCustomerTrackingDP();
			Map condMap= new HashMap();
			/*if(null!=condition&&!Util.isNull(condition.getTitle())){
				condMap.put("title", condition.getTitle());
			}*/
			List<CustomerTracking> list = (List<CustomerTracking>)domainProviderSetImpl.getDao().findByHqlNameAndDomian(customerTrackingDP,"customerTrackingByUid",params);
			return list;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<TrackingInfo> getAllTrackingInfo(){
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider trackingInfoDP = domainProviderSetImpl.getTrackingInfoDP();
			List<TrackingInfo> list = (List<TrackingInfo>)domainProviderSetImpl.getDao().findAllByDomian(trackingInfoDP);
			return list;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}
	
	public TrackingInfo getTrackingInfoById(String id){
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider trackingInfoDP = domainProviderSetImpl.getTrackingInfoDP();
			TrackingInfo trackingInfo = (TrackingInfo)domainProviderSetImpl.getDao().findByIdAndDomain(trackingInfoDP, id);
			return trackingInfo;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	public void saveTrackingInfo(TrackingInfo trackingInfo){
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().saveOrUpdate(trackingInfo);
		} catch (DaoException e) {
			log.error("", e);
		}
	}
	
	@Override
	public void deleteTrackingInfo(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider trackingInfoDP = domainProviderSetImpl.getTrackingInfoDP();
			domainProviderSetImpl.getDao().deleteById(trackingInfoDP, id);
		} catch (DaoException e) {
			log.error("", e);
		} catch (DaoConfigException e) {
			log.error("", e);
		}
	}

	@Override
	public CustomerTracking getCustomerTrackingById(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerTrackingDP = domainProviderSetImpl.getCustomerTrackingDP();
			CustomerTracking customerTracking = (CustomerTracking)domainProviderSetImpl.getDao().findByIdAndDomain(customerTrackingDP, id);
			return customerTracking;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	@Override
	public void deleteCustomerTracking(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerTrackingDP = domainProviderSetImpl.getCustomerTrackingDP();
			domainProviderSetImpl.getDao().deleteById(customerTrackingDP, id);
		} catch (DaoException e) {
			log.error("", e);
		} catch (DaoConfigException e) {
			log.error("", e);
		}
	}
}
